package lry.order;

import com.lry.message.Message;
import com.lry.message.MessageQueue;
import com.lry.producer.DefaultMqProducer;
import com.lry.producer.SendResult;
import com.lry.selector.MessageSelector;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class BasicProducer {

    public static void main(String[] args) throws InterruptedException {

        DefaultMqProducer producer = new DefaultMqProducer("localhost:8084");
        producer.start();

        for(int i=0;i<1000000;i++){
            Message message = new Message();
            message.setBody(("hello world"+i).getBytes(StandardCharsets.UTF_8));
            message.setTopic("topic");

            SendResult result = producer.send(message, new MessageSelector() {
                @Override
                public MessageQueue select(List<MessageQueue> messageQueueList, Message message, Object arg) {
                    //只用0号队列
                    if(arg.equals(1)){
                        return messageQueueList.get(0);
                    }
                    return null;
                }
            },1);

            System.out.println(result);

            Thread.sleep(1000);
        }
    }
}
